﻿using FluentNHibernate.Mapping;
using PCE.Domain;

namespace PCE.Configuration.NH.Mappings
{
	public class CustomerMap : ClassMap<Customer>
	{
		public CustomerMap()
		{
			Id(m => m.Id).GeneratedBy.Identity();

			NaturalId().ReadOnly().Property(m => m.Login);
			
			Map(m => m.Password).Not.Nullable();
			Map(m => m.Email).Not.Nullable();

			Map(m => m.IsCorporate);
			Map(m => m.CompanyName);
			Map(m => m.LegalAddress);
			Map(m => m.PhysicalAddress);
			Map(m => m.TIN);
			Map(m => m.BIN);
			Map(m => m.Ownership);

			HasMany(m => m.Tenders)
				.AsSet()
				.Inverse()
				.KeyColumn("CustomerId")
				.Cascade
				.All();
		}
	}
}